package demo10;
@SuppressWarnings({"all"})
public class Test {
    public static void main(String[] args) throws ClassNotFoundException {
        Person person = new Student();
        //1.通过对象获得
        Class c1 = person.getClass();
        System.out.println(c1.hashCode());

        //2.通过下面的这个forname方法
        Class c2 = Class.forName("demo10.Student");
        System.out.println(c2.hashCode());

        //3.通过类名.class
        Class  c3 = Student.class;
        System.out.println(c3.hashCode());

        //4.包装类有自己的这个class
        Class  c4 = Integer.TYPE;
        System.out.println(c4.hashCode());

        //5.获取父类的
        Class c5 = c1.getSuperclass();
        System.out.println(c5);
        System.out.println(c5.hashCode());
    }
}
class Person{
    String name;

    public Person(String name) {
        this.name = name;
    }

    public Person() {
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                '}';
    }
}
class Student extends Person{
    public Student(){
        this.name="学生";
    }
}
class Teacher extends Person{
    public Teacher(){
        this.name="老师";
    }
}
